﻿//----------------------------------------------------

#region 命名空间

//    版权：
//    作者：
//建立时间：2012-09-11 00:00:33
//    描述：
//----------------------------------------------------
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq;
using WinnerCMS.Data;
using WinnerCMS.Model;
using WinnerCMS.Common;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// 业务逻辑类 WinnerCMS_PayPlatForm 的摘要说明。
    /// </summary>
    public class PaymentMethodManage
    {
        private static readonly PaymentMethodDal MyDAL = new PaymentMethodDal();

        #region 添加

        /// <summary>
        /// 添加
        /// </summary>
        public void Add(PaymentMethod model, ref string strErr)
        {
            if (model.MethodName.Length == 0)
            {
                strErr = "“支付平台名称”不能为空！";
                return;
            }


            if (model.Id == 0)
            {
                MyDAL.Add(model);
            }
            else
            {
                MyDAL.Edit(model);
            }
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        public void Delete(string IDs, UpdatePanel UpdatePanel1)
        {
            if (string.IsNullOrEmpty(IDs))
            {
                MsgBox.Message("至少选择一项。", UpdatePanel1);
            }
            else
            {
                int[] ids = (from x in IDs.Split(',') select int.Parse(x)).ToArray();
                MyDAL.Delete(ids);
            }
        }

        #endregion

        /// <summary>
        /// 审核或者取消审核
        /// </summary>
        /// <param name="ID"></param>
        public void PassOrNo(int ID)
        {
            var state = MyDAL.PassOrNo(ID);

            if (state)
            {
                Log logModel = new Log();
                logModel.Type = "帮助管理";
                logModel.Event = "撤消审核ID" + ID;
                LogManage.Add(logModel);
            }
            else
            {
                Log logModel = new Log();
                logModel.Type = "帮助管理";
                logModel.Event = "通过审核ID" + ID;
                LogManage.Add(logModel);
            }
        }

        #region 加载数据

        /// <summary>
        /// 加载数据
        /// </summary>
        public PaymentMethod GetInfo(int ID)
        {
            return MyDAL.GetInfo(ID);
        }

        #endregion

        public void BindList(RadioButtonList RBL_PaymentMethod)
        {
            IList<PaymentMethod> list = MyDAL.GetList();

            foreach (PaymentMethod model in list)
            {
                ListItem item = new ListItem();
                item.Text = model.MethodName;
                item.Value = model.Id.ToString();

                if (model.IsDefault)
                {
                    item.Selected = true;
                }

                RBL_PaymentMethod.Items.Add(item);
            }
        }

        public IList<PaymentMethod> GetList()
        {
            return MyDAL.GetList();
        }
    }
}